'use strict'

let ws = require('ws').Server
let EventEmitter = require('events').EventEmitter
let userServerConfig = require('../config').userServerConfig
let nodeSessionMgr = require('./nodeSessionMgr')

class UserServer {
  constructor() {
    this.server = null
    this.curId = 1
  }

  //创建WS服务器
  createServer() {
    Log(`用户服务器启动 ${userServerConfig.ip}:${userServerConfig.port}`)
    let self = this
    this.server = new ws({
      host: userServerConfig.ip,
      port: userServerConfig.port
    })
    this.server.on('connection', function(socket) {
      //创建会话
      Log('新的连接')
      nodeSessionMgr.create(self.curId, socket)
      self.curId += 1
    })
  }

  close(socket) {
    session.close()
  }
}
let userServer = new UserServer()
userServer.createServer()
module.exports = userServer
